<?php
// function that get array of cufon fonts
function dt_get_fonts_in( $dir = 'fonts' ){
    $res = array();
    $dirname = dirname(__FILE__). '/../' .$dir;
    if ($handle = opendir( $dirname ) ) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $f_name = preg_split( '/\.[^.]+$/', $file );
                $res[get_stylesheet_directory_uri() . '/' . $dir . '/' .$file] = $f_name[0];
            }
        }
        closedir($handle);
    }
    if( empty($res) ){
        $res['none'] = __( 'no fonts', 'dt-options-fonts_select');
    }
    return $res;
}

// get images for options framework
function dt_get_images_in( $dir = '' ){
    $noimage = get_stylesheet_directory_uri(). '/images/noimage_small.jpg';
    $dirname = dirname(__FILE__). '/../' .$dir;
    $res = $full_dir = $thumbs_dir = array();
    $res['none'] = $noimage;
    
    // full dir
    if ( file_exists($dirname. '/full') && $handle = opendir( $dirname. '/full') ) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && $file != 'Thumb.db' && $file != 'Thumbs.db') {
                $f_name = preg_split( '/\.[^.]+$/', $file );
                $full_dir[$f_name[0]] = $file;
            }
        }
        closedir($handle);
    }
    unset($file);
    
    // thumbs dir
    if ( file_exists($dirname. '/thumbs') && $handle = opendir( $dirname. '/thumbs') ) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && $file != 'Thumb.db' && $file != 'Thumbs.db') {
                $f_name = preg_split( '/\.[^.]+$/', $file );
                $thumbs_dir[$f_name[0]] = $file;
            }
        }
        closedir($handle);
    }
    unset($file);
    asort($full_dir);
    
    foreach( $full_dir as $name=>$file ){
        $full_link = get_stylesheet_directory_uri() . '/' . $dir . '/full/' . $file;
        if( array_key_exists( $name, $thumbs_dir ) ){
            $thumb_link = get_stylesheet_directory_uri() . '/' . $dir . '/thumbs/' . $thumbs_dir[$name];
        }else{
            $thumb_link = $noimage;
        }
        $res[$full_link] = $thumb_link;
    }
    
    return $res;
}

// function return list of social links
function dt_get_soc_links( $type = 'frontend'){
    $base = get_template_directory_uri();
    // links list
    $links = array(
        'AIM'           => 'AIM__png',
        'Behance'		=> 'Behance__png',
        'Blogger'       => 'Blogger__png',
        'Cargo'         => 'Cargo__png',
        'Design Float'  => 'Design_Float__png',
        'Delicious'		=> 'Delicious__png',
        'DesignMoo'     => 'DesignMoo__png',
        'DevianART'	    => 'DeviantART__png',
        'Digg'			=> 'Digg__png',
        'Dribbble'		=> 'Dribbble__png',
//        'DROPBOX'		=> 'ico_Dropbox',
        'Evernote'      => 'Evernote__png',
        'Facebook'		=> 'Facebook__png',
        'Forrst'		=> 'Forrst__png',
        'Flickr'		=> 'Flickr__png',
        'Google'	    => 'Google__png',
        'Google_Buzz'	=> 'Google_Buzz__png',
        'Last_FM'       => 'Last_FM__png',
        'Linkedin'		=> 'Linkedin__png',
//        'MOBYPICTURE'	=> 'ico_MobyPicture',
        'MyScape'		=> 'MyScape__png',
        'Open_ID'       => 'Open_ID__png',
        'PayPal'        => 'PayPal__png',
        'Picasa'		=> 'Picasa__png',
//        'PLIXI'			=> 'ico_Plixi',
        'RSS'			=> 'RSS__png',
        'Share_This'    => 'Share_This__png',
//        'STUBLEUPON'	=> 'ico_StubleUpon',
        'Skype'			=> 'Skype__png',
        'Thumblr'		=> 'Thumblr__png',
        'Twitter'		=> 'Twitter__png',
        'Vimeo'			=> 'Vimeo__png',
        'Wordpress'     => 'Wordpress__png',
        'Yahoo'         => 'Yahoo__png',
        'Yelp'          => 'Yelp__png',
        'Youtube'		=> 'Youtube__png'
    );
    
    if( 'frontend' == $type ) {
        $out_links = '<ul>';
        foreach( $links as $l_name=>$class ){
            $o_class = str_replace('-', '', strtolower($class));
            $ico = str_replace( '__', '.', $class );
            if( of_get_option( 'misc_' .$o_class. '_checkbox' ) ){
                $href = of_get_option( "misc_" .$o_class. "_text", '#' );
                $href = empty($href)?'#':$href;
                $out_links .= <<<HDOCK
                <li>
                    <a href="$href" target="_blank" title="{$l_name}"><img src="{$base}/images/social/{$ico}" width="14" height="14" alt="{$l_name}" /></a>
                </li>
HDOCK;
            }
        }
        
        $out_links .= '</ul>';
        
        return $out_links;
    }else {
        return $links;
    }
}

function dt_get_toptext( $type = 'frontend' ) {
    $links = array(
        'Adress'    => 'adress',
        'Phone'     => 'phone',
        'Skype'     => 'skype',
        'Mail'      => 'mail'
    );
        
    if( 'frontend' == $type ) {
        
        $out_links = '';
        foreach( $links as $title=>$class ) {
            $o_class = str_replace('-', '', strtolower($class));
            if( of_get_option( 'misc_toplinks_' .$o_class. '_checkbox' ) ){
/*                
                $href = of_get_option( "misc_toplinks_" .$o_class. "_href", '#' );
                $href = empty( $href )?'#':$href;
                $href = esc_url( $href );
*/                
                $text = of_get_option( "misc_toplinks_" .$o_class. "_text", '' );
//                $text = esc_attr( $text );
                
                $out_links .= <<<HEREDOCK
                <li>
                    <span class="{$class}">{$text}</span>
                </li>
HEREDOCK;
            }
        }
        
        if( $out_links ) {
            $out_links = '<ul id="topicons">' . $out_links . '</ul>';
        }
        
        
        return $out_links;
        
    }else {
        return $links;
    }
}

// options add custom scripts
add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');
function optionsframework_custom_scripts() { ?>

<script type="text/javascript">
jQuery(document).ready(function() {
    // appearance
    
    // fonts - enable_cufon
    jQuery('#fonts_enable_cufon_checkbox').click(function() {
        jQuery(	'#section-fonts_select').fadeToggle(400);
        jQuery(	'#section-fonts_enable_custom_checkbox').fadeToggle(400);
    });
    
    if (jQuery('#fonts_enable_cufon_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-fonts_select').show();
        jQuery(	'#section-fonts_enable_custom_checkbox').show();
    }else{
        jQuery(	'#section-fonts_select').hide();
        jQuery(	'#section-fonts_enable_custom_checkbox').hide();
    }
    
    // fonts - custom_upload
    jQuery('#fonts_enable_custom_checkbox').click(function() {
        jQuery(	'#section-fonts_custom_uploader').fadeToggle(400);
    });
    
    if (jQuery('#fonts_enable_custom_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-fonts_custom_uploader').show();
    }else{
        jQuery(	'#section-fonts_custom_uploader').hide();
    }
    
    // about - about_textarea
    jQuery('#about_show_about_checkbox').click(function() {
        jQuery(	'#section-about_textarea').fadeToggle(400);
    });
    
    if (jQuery('#about_show_about_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-about_textarea').show();
    }else{
        jQuery(	'#section-about_textarea').hide();
    }
    
    // parallax
    // lv1 custom bg
    jQuery('#lv1_custom_bg_checkbox').click(function() {
        jQuery(	'#section-lv1_custom_db_uploader').fadeToggle(400);
    });
    
    if (jQuery('#lv1_custom_bg_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-lv1_custom_db_uploader').show();
    }else{
        jQuery(	'#section-lv1_custom_db_uploader').hide();
    }
    // lv2 custom bg
    jQuery('#lv2_custom_bg_checkbox').click(function() {
        jQuery(	'#section-lv2_custom_db_uploader').fadeToggle(400);
    });
    
    if (jQuery('#lv2_custom_bg_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-lv2_custom_db_uploader').show();
    }else{
        jQuery(	'#section-lv2_custom_db_uploader').hide();
    }
    // lv3 custom bg
    jQuery('#lv3_custom_bg_checkbox').click(function() {
        jQuery(	'#section-lv3_custom_db_uploader').fadeToggle(400);
    });
    
    if (jQuery('#lv3_custom_bg_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-lv3_custom_db_uploader').show();
    }else{
        jQuery(	'#section-lv3_custom_db_uploader').hide();
    }  
    
    // decor corner
    jQuery('#custom_decor_corner_checkbox').click(function() {
        jQuery(	'#section-custom_decor_corner_uploader').fadeToggle(400);
    });
    
    if (jQuery('#custom_decor_corner_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-custom_decor_corner_uploader').show();
    }else{
        jQuery(	'#section-custom_decor_corner_uploader').hide();
    }
    
    // background
    // top custom bg
    jQuery('#top_custom_bg_checkbox').click(function() {
        jQuery(	'#section-top_custom_db_uploader').fadeToggle(400);
    });
    
    if (jQuery('#top_custom_bg_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-top_custom_db_uploader' ).show();
    }else{
        jQuery(	'#section-top_custom_db_uploader' ).hide();
    }
    // body custom bg
    jQuery('#body_custom_bg_checkbox').click(function() {
        jQuery(	'#section-body_custom_db_uploader').fadeToggle(400);
    });
    
    if (jQuery('#body_custom_bg_checkbox:checked').val() !== undefined) {
        jQuery(	'#section-body_custom_db_uploader').show();
    }else{
        jQuery(	'#section-body_custom_db_uploader').hide();
    }
    
    // MISC
    
    // top block
    jQuery('#misc_top_links .section-checkbox input[type="checkbox"]').click(function() {
        jQuery(this).parents('.section-checkbox').next('#misc_top_links .section-text').fadeToggle(400).next('#misc_top_links .section-text').fadeToggle(400);
        //console.log(this);
    });
    
    jQuery('#misc_top_links .section-checkbox input[type="checkbox"]').not(':checked').each(function( i ){
        jQuery(this).parents('.section-checkbox').next('#misc_top_links .section-text').hide().next('#misc_top_links .section-text').hide();
        //console.log(this);
    });
    
    // soc block
    jQuery('#misc_soc_links .section-checkbox input[type="checkbox"]').click(function() {
        jQuery(this).parents('.section-checkbox').next('#misc_soc_links .section-text').fadeToggle(400);
        //console.log(this);
    });
    
    jQuery('#misc_soc_links .section-checkbox input[type="checkbox"]').not(':checked').each(function( i ){
        jQuery(this).parents('.section-checkbox').next('#misc_soc_links .section-text').hide();
        //console.log(this);
    });
});
</script>
 
<?php
}